<?php

namespace app\models\searchs;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\UserLog;

/**
 * UserLogSearch represents the model behind the search form about `app\models\UserLog`.
 */
class UserLogSearch extends UserLog
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'company_id', 'park_id', 'type', 'date', 'status', 'person_id'], 'integer'],
            [['idcard_img', 'cachet_img'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = UserLog::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'company_id' => $this->company_id,
            'park_id' => $this->park_id,
            'type' => $this->type,
            'date' => $this->date,
            'status' => $this->status,
            'person_id' => $this->person_id,
        ]);

        $query->andFilterWhere(['like', 'idcard_img', $this->idcard_img])
            ->andFilterWhere(['like', 'cachet_img', $this->cachet_img]);

        return $dataProvider;
    }
}
